/*
 * @Author: for range（键值循环）  switch 流程控制
 * @Date: 2021-01-21 16:44:51
 * @LastEditTime: 2021-01-21 17:08:57
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \go_demo\src\05_range_switch\main.go
 */
package main

import "fmt"

func main () {
    /*
    for range
    */
    var str = "你好 world~"
    for k , v := range str {
        fmt.Println("key = ",k, "value = ",v)
        fmt.Printf("—— 键 = %v 值 = %c \n",k,v)
    }

    var arr = []string {"php","java","c","golang"}
    for i := 0; i < len(arr); i++ {
        fmt.Println(arr[i])
    }

    for k , v := range arr {
        fmt.Printf("key = %v value = %v \n",k,v)
    }

    /*
    switch case
    */
    suffix := "c"
    switch suffix {
        
    case "php":
        fmt.Println("文件为PHP")
        //只有在case中明确添加fallthrough关键字，才会继续执行紧跟的下一个case；
        fallthrough
    case "html" :
        fmt.Println("文件为HTML")
    case "go" :
        fmt.Println("文件为GOLANG")
    case "java" :
        fmt.Println("文件为JAVA")
    case "c","c++" :
        fmt.Println("文件为C")
    default :
        fmt.Println("未找到该文件")
    }

    //分支可以使用表达式，这时候switch语句后面不需要再跟判断变量
    var age = 24
    switch {
    case age < 18 :
        fmt.Println("请好好学习")
    case age > 18 :
        fmt.Println("请好好工作")
    }
}